/**
 * cndatacom Inc.
 * Copyright (c) 2014-2014 All Rights Reserved.
 */   
package com.stam.controller;   

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.stam.dal.dataobject.StockUser;
import com.stam.service.StockUserService;

/**  
* 创建时间：2014年5月10日 下午10:23:13  
* 项目名称：stam  
* @author yangjuanying  
* @version 1.0   
* @since JDK 1.6.0_21  
* 文件名称：BaseController.java  
* 类说明：  
*/
@Controller
public class LoginController extends BaseController {
    
    private Logger logger = Logger.getLogger(LoginController.class);
    
    @Autowired
    private StockUserService stockUserService;
    
    @RequestMapping(value="/login.htm",method=RequestMethod.GET)
    public String loginGet(HttpServletResponse response,HttpServletRequest request, ModelMap modelMap){
        return "login.vm";
    }
    
    @RequestMapping(value="/login.htm",method=RequestMethod.POST)
    public String loginPost(HttpServletResponse response,HttpServletRequest request, ModelMap modelMap){
        String userId = request.getParameter("j_username");
        String password = request.getParameter("j_password");
        if(!StringUtils.hasText(userId) || !StringUtils.hasText(password)){
            addMsg(modelMap, "用户名或密码不能为空");
            return "login.vm";
        }
        logger.info("有请求访问登陆页面，获取到的用户userId为："+userId+",密码为："+password);
        StockUser stockUser = stockUserService.validateLoginUser(userId, password);
        if(stockUser == null){
            addMsg(modelMap, "用户名或密码错误");
            return "login.vm";
        }
        return "index.vm";
    }

}
  